var hostname = "http://clouddev.parkingquickly.com";
var protocol = window.location.protocol;
var rest_domain = "/api";

//获取url参数值
var params_obj = null;
function get_querystring(key) {
    if (!params_obj) {
        params_obj = {};
        var params = unescape(decodeURI(window.location.search)).substr(1).split('&');
        for (var item of params) {
            var i = item.indexOf('=');
            if (i < 0)
                continue;
            params_obj[item.substr(0, i)] = item.substr(i + 1);
        }
    }
    return params_obj[key];
}



//人性化时间格式
function human_time(seconds) {
    let human = "";
    if (seconds <= 0)
        return "0分钟";

    let total = Math.max(1, Math.floor(seconds / 60));
    let days = Math.floor(total / (24 * 60));
    let hours = Math.floor(total % (24 * 60) / 60);
    let minutes = Math.floor(total % 60);

    if (days > 0)
        human += `${days}天`;
    if (hours > 0)
        human += `${hours}小时`;
    if (minutes > 0)
        human += `${minutes}分钟`;
    return human;
}

//日期加n天
function addDate(date, days) {
    var d = new Date(date);
    d.setDate(d.getDate() + days);
    var month = d.getMonth() + 1;
    var day = d.getDate();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    var val = d.getFullYear() + "-" + month + "-" + day;
    return val;
}

//月份加n月
function addMonth(date, month) {
    var d = new Date(date);
    d.setMonth(d.getMonth() + month);
    var month = d.getMonth() + 1;
    var day = d.getDate();
    if (month < 10) {
        month = "0" + month;
    }
    if (day < 10) {
        day = "0" + day;
    }
    var val = d.getFullYear() + "-" + month + "-" + day;
    return val;
}

//中文字符
function isChn(str) {
    var reg = /[\u4e00-\u9fa5]/;
    if (!reg.test(str)) {
        return false;
    }
    return true;
}

//字母
function isBig(str) {
    var reg = /[a-zA-Z]/;
    if (!reg.test(str)) {
        return false;
    }
    return true;
}

var echartscolor = ['#564AE0', '#9586F3', '#F8AF08', '#FBD658', '#0B3B95', '#31B0F8', '#4EDEF2', '#BEE57A', '#FFAB7D', '#DEF772', '#96A7D6'];
//数字
function isInteger(obj) {
    var reg = new RegExp(/^(0|[1-9][0-9]*)$/);
    return reg.test(obj);
}

//验证手机号
var checkPhone = function (phone) {
    var reg = /^1[3|4|5|7|8]\d{9}$/g;
    if (!reg.test(phone)) {
        return false;
    }
    return true;
};

//车牌号验证
function isVehicleNumber(vehicleNumber) {
    var result = false;
    if (vehicleNumber.length == 7 || vehicleNumber.length == 8) {
        var express = /^[\u4e00-\u9fa5A-Z0-9]{1}[A-Z0-9]{5}[\u4e00-\u9fa5A-Z0-9]{1,2}$/;
        result = express.test(vehicleNumber);
    }
    return result;
}

//优惠券类型
var coupontype = {
    1: ['时长券', '小时', 'singlecoupontime'],
    2: ['现金券', '元', 'singlecouponmoney']
}

var formatlabeldata = function (e) {
    var newStr = "";
    var namestr = e.name;
    var valuestr = e.value + '张';
    namestr = namestr.substr(0, namestr.length - 3) + '券\n';
    newStr = namestr + valuestr;
    return newStr;
}


// 处理时间差
function dealtimedifference(time, usetime) {
    var valid = 0;
    time = new Date(time).getTime();
    var nowtime = new Date().getTime();
    var diff = nowtime - time;
    if (diff < 0) {
        if (!usetime) {
            valid = 0;
        } else {
            valid = 1;
        }
    } else {
        valid = 2;
    }
    return valid;
}

//有效期
valid = {
    0: '当日',
    1: '一个星期内',
    2: '一个月内'
}